package com.lanou.service;/*
 * @author 马继耿~
 * @date 2023/10/30 15:29
 * @version 1.0
 * */

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou.mapper.MJG_SelectYuCunMapper;
import com.lanou.pojo.PaymentPreEntity;
import com.lanou.pojo.PaymentTempEntity;
import com.lanou.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;

@Service
public class MJG_AdvenceServiceImpl implements MJG_AdvenceService{
    @Autowired
    private MJG_SelectYuCunMapper mjg_selectYuCunMapper;

    @Override
    public JsonResult SelectYuCun(String pageNum, String pageSize) {
        //处理分页查询
        if(pageNum == null || "".equals(pageNum)){
            pageNum="1";
        }
        if(pageSize == null || "".equals(pageSize)){
            pageSize="5";
        }
        PageHelper.startPage(Integer.valueOf(pageNum),Integer.valueOf(pageSize));
        List<PaymentPreEntity> paymentPreEntities = mjg_selectYuCunMapper.SelectYuCun1();
        PageInfo<PaymentPreEntity> paymentTempEntityPageInfo = new PageInfo<>(paymentPreEntities);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(paymentTempEntityPageInfo);
        jsonResult.setStatus(200);

        return jsonResult;
    }

    @Override
    public JsonResult SelectYuCun(String resourceName, String feeUser, String type, String feeItemName, String payType) {
        List<PaymentPreEntity> paymentPreEntities = mjg_selectYuCunMapper.Select(resourceName, feeUser, type, feeItemName, payType);
        PageInfo<PaymentPreEntity> paymentTempEntityPageInfo = new PageInfo<>(paymentPreEntities);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(paymentTempEntityPageInfo);
        jsonResult.setStatus(200);

        return jsonResult;
    }

    @Override
    public void add(PaymentPreEntity paymentPreEntity) {
        // 获取当前时间戳
        long timestamp = System.currentTimeMillis();
        Date date = new Date(timestamp);
        paymentPreEntity.setId(String.valueOf(timestamp));
        paymentPreEntity.setResourceId(String.valueOf(timestamp));
        paymentPreEntity.setBlock("");
        paymentPreEntity.setFeeItemId("");
        paymentPreEntity.setType("payAdd");
        paymentPreEntity.setUseFeeItem("");
        paymentPreEntity.setOperateUser("1");
        paymentPreEntity.setOperateTime(date);
        paymentPreEntity.setPayNo("PY"+timestamp);
        System.out.println(paymentPreEntity);
        mjg_selectYuCunMapper.add(paymentPreEntity);
    }
}
